package com.lucence.util;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;

import com.lucence.a_helloword.Article;

public class ArticleDocument {
	public static Document articleToDocument(Article art){
		Document doc = new Document();
		doc.add(new Field("id", art.getId(), Store.YES, Index.NOT_ANALYZED));
		doc.add(new Field("title", art.getTitle(),Store.YES, Index.ANALYZED));
		doc.add(new Field("content", art.getContent(), Store.YES, Index.ANALYZED));
		return doc;
	}
	
	public static Article articleToDocument(Document document){
		Article article = new Article();
		article.setId(document.get("id"));
		article.setTitle(document.get("title"));
		article.setContent(document.get("content"));
		return article;
	}
}
